package com.powernode.config;

import com.powernode.constant.Constants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DelayConfig {

    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(Constants.EXCHANGE_DELAY_NAME, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue delayQueue() {
        return new Queue(Constants.QUEUE_DELAY_NAME);
    }

    @Bean
    public Binding delayBinding(CustomExchange customExchange, Queue delayQueue) {
        return BindingBuilder.bind(delayQueue).to(customExchange).with(Constants.QUEUE_DELAY_NAME).noargs();
    }
}
